home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / sun / volume1 / calctool / part02 < prev    next >
Encoding:
Internet Message Format  |  1989-06-29  |  38.0 KB

  1. Path: uunet!husc6!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  2. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  3. Newsgroups: comp.sources.sun
  4. Subject: v01i039:  Calctool, a calculator for your Sun, Part02/02
  5. Message-ID: <Jun.29.22.14.29.1989.12588@dartagnan.rutgers.edu>
  6. Date: 30 Jun 89 02:14:32 GMT
  7. Organization: Rutgers Univ., New Brunswick, N.J.
  8. Lines: 1075
  9. Approved: mcgrew@aramis.rutgers.edu
  10.  
  11. Submitted-by: chuck@melmac.harris-atd.com (Chuck Musciano)
  12. Posting-number: Volume 1, Issue 39
  13. Archive-name: calctool/part02
  14.  
  15. #! /bin/sh
  16. # This is a shell archive, meaning:
  17. # 1. Remove everything above the #! /bin/sh line.
  18. # 2. Save the resulting text in a file.
  19. # 3. Execute the file with /bin/sh (not csh) to create the files:
  20. #    keys.h
  21. #    manifest.h
  22. #    memory.c
  23. #    ops.c
  24. #    screen.c
  25. # This archive created: Thu Jun 29 21:58:43 1989
  26. export PATH; PATH=/bin:$PATH
  27. echo shar: extracting "'keys.h'" '(3654 characters)'
  28. if test -f 'keys.h'
  29. then
  30.     echo shar: will not over-write existing file "'keys.h'"
  31. else
  32. sed 's/^    X//' << \SHAR_EOF > 'keys.h'
  33.     X/************************************************************************/
  34.     X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  35.     X/*                                    */
  36.     X/*    Permission to use, copy, modify, and distribute this software    */
  37.     X/*    and its documentation for any purpose and without fee is    */
  38.     X/*    hereby granted, provided that the above copyright notice    */
  39.     X/*    appear in all copies and that both that copyright notice and    */
  40.     X/*    this permission notice appear in supporting documentation, and    */
  41.     X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  42.     X/*    used in advertising or publicity pertaining to distribution    */
  43.     X/*    of the software without specific, written prior permission.    */
  44.     X/*    Chuck Musciano and Harris Corporation make no representations    */
  45.     X/*    about the suitability of this software for any purpose.  It is    */
  46.     X/*    provided "as is" without express or implied warranty.        */
  47.     X/************************************************************************/
  48.     X
  49.     X/************************************************************************/
  50.     X/*                                    */
  51.     X/*    Key opcode definitions                        */
  52.     X/*                                    */
  53.     X/************************************************************************/
  54.     X
  55.     X#define        BINARY_OP        0x00010000
  56.     X#define        UNARY_OP        0x00020000
  57.     X
  58.     X#define        is_binary(x)        ((x) & BINARY_OP)
  59.     X#define        is_unary(x)        ((x) & UNARY_OP)
  60.     X#define        is_digit(x)        ((x) >= DIGIT_0 && (x) <= DIGIT_EE)
  61.     X#define        prec(x)            ((x) >> 20)
  62.     X
  63.     X#define        NO_OP            -1
  64.     X#define        DIGIT_0            0
  65.     X#define        DIGIT_1            1
  66.     X#define        DIGIT_2            2
  67.     X#define        DIGIT_3            3
  68.     X#define        DIGIT_4            4
  69.     X#define        DIGIT_5            5
  70.     X#define        DIGIT_6            6
  71.     X#define        DIGIT_7            7
  72.     X#define        DIGIT_8            8
  73.     X#define        DIGIT_9            9
  74.     X#define        DIGIT_A            10
  75.     X#define        DIGIT_B            11
  76.     X#define        DIGIT_C            12
  77.     X#define        DIGIT_D            13
  78.     X#define        DIGIT_E            14
  79.     X#define        DIGIT_F            15
  80.     X#define        DIGIT_DOT        16
  81.     X#define        DIGIT_CHS        17
  82.     X#define        DIGIT_EE        18
  83.     X
  84.     X#define        ADD_OP            (19 | BINARY_OP | (2 << 20))
  85.     X#define        AND_OP            (20 | BINARY_OP | (5 << 20))
  86.     X#define        CLEAR_OP        (21 | UNARY_OP)
  87.     X#define        CLOSE_OP        (22 | UNARY_OP)
  88.     X#define        COS_OP            (23 | UNARY_OP)
  89.     X#define        DIV_OP            (24 | BINARY_OP | (3 << 20))
  90.     X#define        EQUAL_OP        (25 | UNARY_OP)
  91.     X#define        ERASE_OP        (26 | UNARY_OP)
  92.     X#define        EXC_OP            (27 | UNARY_OP)
  93.     X#define        EXP_OP            (28 | UNARY_OP)
  94.     X#define        E_OP            (29 | UNARY_OP)
  95.     X#define        FACT_OP            (30 | UNARY_OP)
  96.     X#define        FIX_OP            (31 | UNARY_OP)
  97.     X#define        ICOS_OP            (32 | UNARY_OP)
  98.     X#define        INT_OP            (33 | UNARY_OP)
  99.     X#define        INVEE_OP        (34 | UNARY_OP)
  100.     X#define        INVERT_OP        (35 | UNARY_OP)
  101.     X#define        ISIN_OP            (36 | UNARY_OP)
  102.     X#define        ITAN_OP            (37 | UNARY_OP)
  103.     X#define        LN_OP            (38 | UNARY_OP)
  104.     X#define        LOG_OP            (39 | UNARY_OP)
  105.     X#define        LPAREN_OP        (40 | UNARY_OP  | (0 << 20))
  106.     X#define        LSL_OP            (41 | BINARY_OP | (3 << 20))
  107.     X#define        MUL_OP            (42 | BINARY_OP | (3 << 20))
  108.     X#define        NOT_OP            (43 | UNARY_OP)
  109.     X#define        OR_OP            (44 | BINARY_OP | (6 << 20))
  110.     X#define        OVER_OP            (45 | UNARY_OP)
  111.     X#define        PI_OP            (46 | UNARY_OP)
  112.     X#define        POINT_OP        (47 | UNARY_OP)
  113.     X#define        POW_OP            (48 | UNARY_OP)
  114.     X#define        QUIT_OP            (49 | UNARY_OP)
  115.     X#define        RCL_OP            (50 | UNARY_OP)
  116.     X#define        ROL_OP            (51 | BINARY_OP | (3 << 20))
  117.     X#define        ROOT_OP            (52 | BINARY_OP | (4 << 20))
  118.     X#define        ROR_OP            (53 | BINARY_OP | (3 << 20))
  119.     X#define        RPAREN_OP        (54 | UNARY_OP  | (1 << 20))
  120.     X#define        RSA_OP            (55 | BINARY_OP | (3 << 20))
  121.     X#define        RSL_OP            (56 | BINARY_OP | (3 << 20))
  122.     X#define        SIN_OP            (57 | UNARY_OP)
  123.     X#define        SQRT_OP            (58 | UNARY_OP)
  124.     X#define        SQR_OP            (59 | UNARY_OP)
  125.     X#define        STO_OP            (60 | UNARY_OP)
  126.     X#define        SUB_OP            (61 | BINARY_OP | (2 << 20))
  127.     X#define        TAN_OP            (62 | UNARY_OP)
  128.     X#define        TRUNC_OP        (63 | UNARY_OP)
  129.     X#define        XOR_OP            (64 | BINARY_OP | (6 << 20))
  130.     X#define        Y2X_OP            (65 | BINARY_OP | (4 << 20))
  131. SHAR_EOF
  132. if test 3654 -ne "`wc -c < 'keys.h'`"
  133. then
  134.     echo shar: error transmitting "'keys.h'" '(should have been 3654 characters)'
  135. fi
  136. fi # end of overwriting check
  137. echo shar: extracting "'manifest.h'" '(1721 characters)'
  138. if test -f 'manifest.h'
  139. then
  140.     echo shar: will not over-write existing file "'manifest.h'"
  141. else
  142. sed 's/^    X//' << \SHAR_EOF > 'manifest.h'
  143.     X/************************************************************************/
  144.     X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  145.     X/*                                    */
  146.     X/*    Permission to use, copy, modify, and distribute this software    */
  147.     X/*    and its documentation for any purpose and without fee is    */
  148.     X/*    hereby granted, provided that the above copyright notice    */
  149.     X/*    appear in all copies and that both that copyright notice and    */
  150.     X/*    this permission notice appear in supporting documentation, and    */
  151.     X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  152.     X/*    used in advertising or publicity pertaining to distribution    */
  153.     X/*    of the software without specific, written prior permission.    */
  154.     X/*    Chuck Musciano and Harris Corporation make no representations    */
  155.     X/*    about the suitability of this software for any purpose.  It is    */
  156.     X/*    provided "as is" without express or implied warranty.        */
  157.     X/************************************************************************/
  158.     X
  159.     X/************************************************************************/
  160.     X/*                                    */
  161.     X/*    Manifest constants                        */
  162.     X/*                                    */
  163.     X/************************************************************************/
  164.     X
  165.     X#define        PRIVATE            static
  166.     X#define        PUBLIC            extern
  167.     X
  168.     X#define        PI            ((double) 3.14159265358979323846)
  169.     X#define        E            ((double) 2.71828182845904523536)
  170.     X
  171.     X#define        SCIENTIFIC        0
  172.     X#define        PROGRAMMER        2
  173.     X
  174.     X#define        BINARY            2
  175.     X#define        OCTAL            8
  176.     X#define        DECIMAL            10
  177.     X#define        HEXADECIMAL        16
  178.     X
  179.     X#define        DEG            0
  180.     X#define        RAD            1
  181.     X#define        GRAD            2
  182.     X
  183.     X#define        MAX_MEMORY        42
  184.     X#define        MAX_STACK        100
  185.     X
  186.     X#define        index_of(x)        ((x == BINARY)? 1 : ((x == OCTAL)? 3 : 4))
  187.     X
  188.     X#ifndef    NULL
  189.     X#define        NULL            0
  190.     X#endif    NULL
  191.     X
  192.     X#ifndef    TRUE
  193.     X#define        TRUE            1
  194.     X#define        FALSE            0
  195.     X#endif    TRUE
  196. SHAR_EOF
  197. if test 1721 -ne "`wc -c < 'manifest.h'`"
  198. then
  199.     echo shar: error transmitting "'manifest.h'" '(should have been 1721 characters)'
  200. fi
  201. fi # end of overwriting check
  202. echo shar: extracting "'memory.c'" '(4276 characters)'
  203. if test -f 'memory.c'
  204. then
  205.     echo shar: will not over-write existing file "'memory.c'"
  206. else
  207. sed 's/^    X//' << \SHAR_EOF > 'memory.c'
  208.     X/************************************************************************/
  209.     X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  210.     X/*                                    */
  211.     X/*    Permission to use, copy, modify, and distribute this software    */
  212.     X/*    and its documentation for any purpose and without fee is    */
  213.     X/*    hereby granted, provided that the above copyright notice    */
  214.     X/*    appear in all copies and that both that copyright notice and    */
  215.     X/*    this permission notice appear in supporting documentation, and    */
  216.     X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  217.     X/*    used in advertising or publicity pertaining to distribution    */
  218.     X/*    of the software without specific, written prior permission.    */
  219.     X/*    Chuck Musciano and Harris Corporation make no representations    */
  220.     X/*    about the suitability of this software for any purpose.  It is    */
  221.     X/*    provided "as is" without express or implied warranty.        */
  222.     X/************************************************************************/
  223.     X
  224.     X/************************************************************************/
  225.     X/*                                    */
  226.     X/*    Module:        memory.c                    */
  227.     X/*                                    */
  228.     X/*    Function:    Manage calculator memories            */
  229.     X/*                                    */
  230.     X/*    Public Names:    store_proc    store a value            */
  231.     X/*            recall_proc    recall a value            */
  232.     X/*            exchange_proc    exchange a value and a memory    */
  233.     X/*            do_store    store in memory            */
  234.     X/*            do_recall    recall from memory        */
  235.     X/*            do_exchange    exchange with memory        */
  236.     X/*                                    */
  237.     X/*    Change History:    17 Nov 86    Creation            */
  238.     X/*            22 May 87    Added do_* procs        */
  239.     X/*                                    */
  240.     X/************************************************************************/
  241.     X
  242.     X#include    <suntool/sunview.h>
  243.     X#include    <suntool/panel.h>
  244.     X
  245.     X#include    "manifest.h"
  246.     X#include    "globals.h"
  247.     X
  248.     X#define        HAS_STORE        0
  249.     X#define        NO_STORE        1
  250.     X
  251.     XPUBLIC    Panel    keys;
  252.     XPUBLIC    struct    pixfont    *key_font;
  253.     X
  254.     XPRIVATE    double    memory[MAX_MEMORY] = {0.0};
  255.     XPRIVATE    char    mem_image[MAX_MEMORY][60];
  256.     XPRIVATE    int    mem_count = 1;
  257.     XPRIVATE    Menu    menu = NULL;
  258.     X
  259.     XPRIVATE    update_menu(store)
  260.     X
  261.     Xint    store;
  262.     X
  263.     X{    int    i;
  264.     X
  265.     X    if (menu)
  266.     X       menu_destroy(menu);
  267.     X    menu = menu_create(MENU_INITIAL_SELECTION, MENU_DEFAULT, 0);
  268.     X    for (i = 0; i < mem_count; i++) {
  269.     X       sprintf(mem_image[i], "%2d: ", i);
  270.     X       convert_value(memory[i], &(mem_image[i][4]));
  271.     X       menu_set(menu, 
  272.     X                  MENU_ITEM, 
  273.     X                     MENU_STRING, mem_image[i], 
  274.     X                     MENU_FONT, key_font, 
  275.     X                     MENU_VALUE, i + 1, 
  276.     X                     0, 
  277.     X                  0);
  278.     X       }
  279.     X    if (store && mem_count < MAX_MEMORY)
  280.     X       menu_set(menu, 
  281.     X                  MENU_ITEM, 
  282.     X                     MENU_STRING, "New Memory", 
  283.     X                     MENU_FONT, key_font, 
  284.     X                     MENU_VALUE, i + 1, 
  285.     X                     0, 
  286.     X                  0);
  287.     X    menu_set(menu, MENU_DEFAULT, 1, 0);
  288.     X}
  289.     X
  290.     XPUBLIC    do_store(slot)
  291.     X
  292.     Xint    slot;
  293.     X
  294.     X{
  295.     X    memory[slot] = v_stack[v_top];
  296.     X}
  297.     X
  298.     XPUBLIC    store_proc(item, event)
  299.     X
  300.     XPanel_item    item;
  301.     XEvent        *event;
  302.     X
  303.     X{    int    slot;
  304.     X
  305.     X    if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  306.     X       keyboard(event_id(event));
  307.     X    else {
  308.     X       convert_display();
  309.     X       if (event_id(event) == MS_RIGHT) {
  310.     X          update_menu(TRUE);
  311.     X          if (slot = (int) menu_show(menu, keys, event, 0)) {
  312.     X             do_store(--slot);
  313.     X             if (slot == mem_count)
  314.     X                mem_count++;
  315.     X             }
  316.     X          }
  317.     X       else
  318.     X          do_store(0);
  319.     X       }
  320.     X}
  321.     X
  322.     XPUBLIC    do_recall(slot)
  323.     X
  324.     Xint    slot;
  325.     X
  326.     X{
  327.     X    v_stack[v_top] = memory[slot];
  328.     X    update_display();
  329.     X}
  330.     X
  331.     XPUBLIC    recall_proc(item, event)
  332.     X
  333.     XPanel_item    item;
  334.     XEvent        *event;
  335.     X
  336.     X{    int    slot;
  337.     X
  338.     X    if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  339.     X       keyboard(event_id(event));
  340.     X    else {
  341.     X       clear_entry();
  342.     X       if (event_id(event) == MS_RIGHT) {
  343.     X          update_menu(FALSE);
  344.     X          if (slot = (int) menu_show(menu, keys, event, 0))
  345.     X             do_recall(--slot);
  346.     X          }
  347.     X       else
  348.     X          do_recall(0);
  349.     X       }
  350.     X}
  351.     X
  352.     XPUBLIC    do_exchange(slot)
  353.     X
  354.     Xint    slot;
  355.     X
  356.     X{    double    temp;
  357.     X
  358.     X    temp = v_stack[v_top];
  359.     X    v_stack[v_top] = memory[slot];
  360.     X    memory[slot] = temp;
  361.     X    update_display();
  362.     X}
  363.     X
  364.     XPUBLIC    exchange_proc(item, event)
  365.     X
  366.     XPanel_item    item;
  367.     XEvent        *event;
  368.     X
  369.     X{    int    slot;
  370.     X
  371.     X    if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  372.     X       keyboard(event_id(event));
  373.     X    else {
  374.     X       convert_display();
  375.     X       if (event_id(event) == MS_RIGHT) {
  376.     X          update_menu(FALSE);
  377.     X          if (slot = (int) menu_show(menu, keys, event, 0))
  378.     X             do_exchange(--slot);
  379.     X          }
  380.     X       else
  381.     X          do_exchange(0);
  382.     X       }
  383.     X}
  384. SHAR_EOF
  385. if test 4276 -ne "`wc -c < 'memory.c'`"
  386. then
  387.     echo shar: error transmitting "'memory.c'" '(should have been 4276 characters)'
  388. fi
  389. fi # end of overwriting check
  390. echo shar: extracting "'ops.c'" '(8116 characters)'
  391. if test -f 'ops.c'
  392. then
  393.     echo shar: will not over-write existing file "'ops.c'"
  394. else
  395. sed 's/^    X//' << \SHAR_EOF > 'ops.c'
  396.     X/************************************************************************/
  397.     X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  398.     X/*                                    */
  399.     X/*    Permission to use, copy, modify, and distribute this software    */
  400.     X/*    and its documentation for any purpose and without fee is    */
  401.     X/*    hereby granted, provided that the above copyright notice    */
  402.     X/*    appear in all copies and that both that copyright notice and    */
  403.     X/*    this permission notice appear in supporting documentation, and    */
  404.     X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  405.     X/*    used in advertising or publicity pertaining to distribution    */
  406.     X/*    of the software without specific, written prior permission.    */
  407.     X/*    Chuck Musciano and Harris Corporation make no representations    */
  408.     X/*    about the suitability of this software for any purpose.  It is    */
  409.     X/*    provided "as is" without express or implied warranty.        */
  410.     X/************************************************************************/
  411.     X
  412.     X/************************************************************************/
  413.     X/*                                    */
  414.     X/*    Module:        ops.c                        */
  415.     X/*                                    */
  416.     X/*    Function:    Perform actual calculation            */
  417.     X/*                                    */
  418.     X/*    Public Names:    do_unary    handle unary operators        */
  419.     X/*            do_binary    handle binary operators        */
  420.     X/*            op_str        return a operator string    */
  421.     X/*                                    */
  422.     X/*    Change History:    17 Nov 86    Creation            */
  423.     X/*                                    */
  424.     X/************************************************************************/
  425.     X
  426.     X#include    <math.h>
  427.     X
  428.     X#include    "manifest.h"
  429.     X#include    "globals.h"
  430.     X#include    "keys.h"
  431.     X
  432.     X#define        low_order(b, x)        ((((unsigned) 0xffffffff) >> (32 - (b))) & (x))
  433.     X
  434.     XPRIVATE    pop_op()
  435.     X
  436.     X{    int    i, temp;
  437.     X
  438.     X    if (curr_mode != SCIENTIFIC && o_stack[o_top - 1]) {
  439.     X       v_stack[v_top] = (double) low_order(curr_width[index_of(curr_base)], (unsigned int) v_stack[v_top]);
  440.     X       v_stack[v_top - 1] = (double) low_order(curr_width[index_of(curr_base)], (unsigned int) v_stack[v_top - 1]);
  441.     X       }
  442.     X    switch (o_stack[--o_top]) {
  443.     X       case ADD_OP    : v_stack[v_top - 1] += v_stack[v_top];
  444.     X                       break;
  445.     X       case AND_OP    : temp = ((unsigned int) v_stack[v_top - 1]) & ((unsigned int) v_stack[v_top]);
  446.     X                       v_stack[v_top - 1] = (double) temp;
  447.     X                       break;
  448.     X       case DIV_OP    : v_stack[v_top - 1] /= v_stack[v_top];
  449.     X                       break;
  450.     X       case LPAREN_OP : return;
  451.     X                   break;
  452.     X       case LSL_OP    : temp = ((unsigned int) v_stack[v_top - 1]) << ((unsigned int) v_stack[v_top]);
  453.     X                       v_stack[v_top - 1] = (double) temp;
  454.     X                       break;
  455.     X       case MUL_OP    : v_stack[v_top - 1] *= v_stack[v_top];
  456.     X                       break;
  457.     X       case OR_OP     : temp = ((unsigned int) v_stack[v_top - 1]) | ((unsigned int) v_stack[v_top]);
  458.     X                       v_stack[v_top - 1] = (double) temp;
  459.     X                       break;
  460.     X       case ROL_OP    : for (i = (unsigned int) v_stack[v_top], temp = (unsigned int) v_stack[v_top - 1]; i; i--)
  461.     X                      temp = (temp << 1) + ((((unsigned) temp) >> (curr_width[index_of(curr_base)] - 1)) & 1);
  462.     X                   v_stack[v_top - 1] = (double) low_order(curr_width[index_of(curr_base)], temp);
  463.     X                       break;
  464.     X       case ROOT_OP   : v_stack[v_top - 1] = pow(v_stack[v_top - 1], 1.0 / v_stack[v_top]);
  465.     X                       break;
  466.     X       case ROR_OP    : for (i = (unsigned int) v_stack[v_top], temp = (unsigned int) v_stack[v_top - 1]; i; i--)
  467.     X                      temp = (((unsigned) temp) >> 1) + ((temp & 1) << (curr_width[index_of(curr_base)] - 1));
  468.     X                   v_stack[v_top - 1] = (double) low_order(curr_width[index_of(curr_base)], temp);
  469.     X                       break;
  470.     X       case RSA_OP    : temp = ((unsigned int) v_stack[v_top - 1]) >> ((unsigned int) v_stack[v_top]);
  471.     X                       v_stack[v_top - 1] = (double) temp;
  472.     X                       break;
  473.     X       case RSL_OP    : temp = ((unsigned int) ((unsigned int) v_stack[v_top - 1])) >> ((unsigned int) v_stack[v_top]);
  474.     X                       v_stack[v_top - 1] = (double) temp;
  475.     X                       break;
  476.     X       case SUB_OP    : v_stack[v_top - 1] -= v_stack[v_top];
  477.     X                       break;
  478.     X       case XOR_OP    : temp = ((unsigned int) v_stack[v_top - 1]) ^ ((unsigned int) v_stack[v_top]);
  479.     X                       v_stack[v_top - 1] = (double) temp;
  480.     X                       break;
  481.     X       case Y2X_OP    : v_stack[v_top - 1] = pow(v_stack[v_top - 1], v_stack[v_top]);
  482.     X                       break;
  483.     X       }
  484.     X    v_top--;
  485.     X}
  486.     X
  487.     XPRIVATE    reduce_stack(pr)
  488.     X
  489.     Xint    pr;
  490.     X
  491.     X{
  492.     X    while (o_top > 0 && pr <= prec(o_stack[o_top - 1]))
  493.     X       pop_op();
  494.     X}
  495.     X
  496.     XPRIVATE    double    to_rads(val)
  497.     X
  498.     Xdouble    val;
  499.     X
  500.     X{
  501.     X    if (trig_mode == DEG)
  502.     X       return(val / 180.0 * PI);
  503.     X    else if (trig_mode == GRAD)
  504.     X       return(val / 200.0 * PI);
  505.     X    else
  506.     X       return(val);
  507.     X}
  508.     X
  509.     XPRIVATE    double    from_rads(val)
  510.     X
  511.     Xdouble    val;
  512.     X
  513.     X{
  514.     X    if (trig_mode == DEG)
  515.     X       return(val / PI * 180.0);
  516.     X    else if (trig_mode == GRAD)
  517.     X       return(val / PI * 200.0);
  518.     X    else
  519.     X       return(val);
  520.     X}
  521.     X
  522.     XPUBLIC    char    *op_str(op)
  523.     X
  524.     Xint    op;
  525.     X
  526.     X{
  527.     X    switch (op) {
  528.     X       case ADD_OP    : return("+");
  529.     X       case AND_OP    : return("&");
  530.     X       case DIV_OP    : return("\205");
  531.     X       case LPAREN_OP : return("(");
  532.     X       case LSL_OP    : return("\200");
  533.     X       case MUL_OP    : return("X");
  534.     X       case OR_OP     : return("|");
  535.     X       case ROL_OP    : return("\202");
  536.     X       case ROOT_OP   : return("\207\210");
  537.     X       case ROR_OP    : return("\203");
  538.     X       case RSA_OP    : return("\204");
  539.     X       case RSL_OP    : return("\201");
  540.     X       case SUB_OP    : return("-");
  541.     X       case XOR_OP    : return("^");
  542.     X       case Y2X_OP    : return("\206");
  543.     X       default      : return("");
  544.     X       }
  545.     X}
  546.     X
  547.     XPUBLIC    do_unary(op)
  548.     X
  549.     Xint    op;
  550.     X
  551.     X{    int    temp;
  552.     X
  553.     X    convert_display();
  554.     X    switch (op) {
  555.     X       case CLEAR_OP  : v_stack[v_top = 0] = 0.0;
  556.     X                   o_top = 0;
  557.     X                   break;
  558.     X       case ERASE_OP  : clear_entry();
  559.     X                   do_digit(DIGIT_0);
  560.     X                   break;
  561.     X       case EQUAL_OP  : reduce_stack(-1);
  562.     X                   break;
  563.     X       case LPAREN_OP : o_stack[o_top++] = LPAREN_OP;
  564.     X                   break;
  565.     X       case RPAREN_OP : reduce_stack(prec(op));
  566.     X                   o_top--;
  567.     X                   break;
  568.     X       case INVEE_OP  : ee_mode = FALSE;
  569.     X                   break;
  570.     X       case COS_OP    : v_stack[v_top] = cos(to_rads(v_stack[v_top]));
  571.     X                      break;
  572.     X       case EXP_OP    : v_stack[v_top] = exp(v_stack[v_top]);
  573.     X                      break;
  574.     X       case E_OP      : v_stack[v_top] = E;
  575.     X                      break;
  576.     X       case FACT_OP   : temp = (int) v_stack[v_top];
  577.     X                      if (temp < 0 || temp > 170)
  578.     X                         v_stack[v_top] /= 0.0;
  579.     X                      else if (temp == 0)
  580.     X                         v_stack[v_top] = 1.0;
  581.     X                      else
  582.     X                         for (v_stack[v_top] = 1.0; temp; temp--)
  583.     X                            v_stack[v_top] *= (double) temp;
  584.     X                      break;
  585.     X       case ICOS_OP   : v_stack[v_top] = from_rads(acos(v_stack[v_top]));
  586.     X                      break;
  587.     X       case INT_OP    : v_stack[v_top] = (double) ((int) v_stack[v_top]);
  588.     X                      break;
  589.     X       case ISIN_OP   : v_stack[v_top] = from_rads(asin(v_stack[v_top]));
  590.     X                      break;
  591.     X       case ITAN_OP   : v_stack[v_top] = from_rads(atan(v_stack[v_top]));
  592.     X                      break;
  593.     X       case LN_OP     : v_stack[v_top] = log(v_stack[v_top]);
  594.     X                      break;
  595.     X       case LOG_OP    : v_stack[v_top] = log10(v_stack[v_top]);
  596.     X                      break;
  597.     X       case NOT_OP    : v_stack[v_top] = (double) low_order(curr_width[index_of(curr_base)], (~ (unsigned int) v_stack[v_top]));
  598.     X                      break;
  599.     X       case OVER_OP   : v_stack[v_top] = 1.0 / v_stack[v_top];
  600.     X                      break;
  601.     X       case PI_OP     : v_stack[v_top] = PI;
  602.     X                      break;
  603.     X       case POW_OP    : v_stack[v_top] = pow(10.0, v_stack[v_top]);
  604.     X                      break;
  605.     X       case SIN_OP    : v_stack[v_top] = sin(to_rads(v_stack[v_top]));
  606.     X                      break;
  607.     X       case SQRT_OP   : v_stack[v_top] = sqrt(v_stack[v_top]);
  608.     X                      break;
  609.     X       case SQR_OP    : v_stack[v_top] *= v_stack[v_top];
  610.     X                      break;
  611.     X       case TAN_OP    : v_stack[v_top] = tan(to_rads(v_stack[v_top]));
  612.     X                      break;
  613.     X       case TRUNC_OP  : if (curr_width[0] != -1) {
  614.     X                         v_stack[v_top] *= pow(10.0, (double) curr_width[0]);
  615.     X                         v_stack[v_top] = (double) ((int) v_stack[v_top]);
  616.     X                         v_stack[v_top] /= pow(10.0, (double) curr_width[0]);
  617.     X                         }
  618.     X                       break;
  619.     X          }
  620.     X    update_display();
  621.     X}
  622.     X
  623.     XPUBLIC    do_binary(op)
  624.     X
  625.     Xint    op;
  626.     X
  627.     X{
  628.     X    convert_display();
  629.     X    reduce_stack(prec(op));
  630.     X    o_stack[o_top++] = op;
  631.     X    v_top += 1;
  632.     X    v_stack[v_top] = v_stack[v_top - 1];
  633.     X    update_display();
  634.     X}
  635. SHAR_EOF
  636. if test 8116 -ne "`wc -c < 'ops.c'`"
  637. then
  638.     echo shar: error transmitting "'ops.c'" '(should have been 8116 characters)'
  639. fi
  640. fi # end of overwriting check
  641. echo shar: extracting "'screen.c'" '(16521 characters)'
  642. if test -f 'screen.c'
  643. then
  644.     echo shar: will not over-write existing file "'screen.c'"
  645. else
  646. sed 's/^    X//' << \SHAR_EOF > 'screen.c'
  647.     X/************************************************************************/
  648.     X/*    Copyright 1988 by Chuck Musciano and Harris Corporation        */
  649.     X/*                                    */
  650.     X/*    Permission to use, copy, modify, and distribute this software    */
  651.     X/*    and its documentation for any purpose and without fee is    */
  652.     X/*    hereby granted, provided that the above copyright notice    */
  653.     X/*    appear in all copies and that both that copyright notice and    */
  654.     X/*    this permission notice appear in supporting documentation, and    */
  655.     X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  656.     X/*    used in advertising or publicity pertaining to distribution    */
  657.     X/*    of the software without specific, written prior permission.    */
  658.     X/*    Chuck Musciano and Harris Corporation make no representations    */
  659.     X/*    about the suitability of this software for any purpose.  It is    */
  660.     X/*    provided "as is" without express or implied warranty.        */
  661.     X/************************************************************************/
  662.     X
  663.     X/************************************************************************/
  664.     X/*                                    */
  665.     X/*    Module:        screen.c                    */
  666.     X/*                                    */
  667.     X/*    Function:    Create calculator display            */
  668.     X/*                                    */
  669.     X/*    Public Names:    create_screen    create the screen        */
  670.     X/*            invert_proc    invert the keyboard        */
  671.     X/*            blink        flash a key            */
  672.     X/*            main        entry point            */
  673.     X/*                                    */
  674.     X/*    Change History:    11 Nov 86    Creation            */
  675.     X/*                                    */
  676.     X/************************************************************************/
  677.     X
  678.     X#include    <stdio.h>
  679.     X
  680.     X#include    <suntool/sunview.h>
  681.     X#include    <suntool/panel.h>
  682.     X#include    <suntool/canvas.h>
  683.     X
  684.     X#include    "manifest.h"
  685.     X#include    "globals.h"
  686.     X#include    "keys.h"
  687.     X
  688.     X#define        CLOSE_KEY            key[0]
  689.     X#define        INVERSE_KEY            key[1]
  690.     X#define        CLEAR_KEY            key[2]
  691.     X#define        FIRST_KEY            3
  692.     X#define        LAST_KEY            37
  693.     X
  694.     X#define        k(s1, s2, s3, s4, o1, o2, o3, o4, p)    {{s1, s2, s3, s4}, {o1, o2, o3, o4}, {NULL, NULL, NULL, NULL}, NULL, p}
  695.     X#define        valid_key(x)                ((x) > DIGIT_F || (x) < curr_base)
  696.     X
  697.     XPRIVATE    close_proc();
  698.     XPRIVATE    event_proc();
  699.     XPRIVATE    key_proc();
  700.     XPRIVATE    radix_proc();
  701.     XPRIVATE    kb_proc();
  702.     X
  703.     XPUBLIC    store_proc();
  704.     XPUBLIC    recall_proc();
  705.     XPUBLIC    exchange_proc();
  706.     XPUBLIC    fix_proc();
  707.     XPUBLIC    invert_proc();
  708.     X
  709.     Xtypedef    struct    key_rec    *key_ptr;
  710.     X
  711.     Xstruct    key_rec    {char        *label[4];
  712.     X         int        opcode[4];
  713.     X         struct    pixrect    *image[4];
  714.     X         Panel_item    item;
  715.     X         int        (*proc)();
  716.     X        };
  717.     X
  718.     XFrame    bf;
  719.     XPanel    keys, sw;
  720.     XCanvas    display;
  721.     Xstruct    pixfont    *key_font;
  722.     X
  723.     XPRIVATE    short    mask_bits[] = {0xaaaa, 0x5555};
  724.     Xmpr_static(mask, 16, 2, 1, mask_bits);
  725.     X
  726.     XPRIVATE    struct    key_rec    key[] = {
  727.     X    k(       "Close",         "Quit",        "Close",         "Quit",  CLOSE_OP,   QUIT_OP,  CLOSE_OP,   QUIT_OP,    close_proc),
  728.     X    k(     "Inverse",      "Inverse",      "Inverse",      "Inverse", INVERT_OP, INVERT_OP, INVERT_OP, INVERT_OP,   invert_proc),
  729.     X    k(       "Erase",        "Clear",        "Erase",        "Clear",  ERASE_OP,  CLEAR_OP,  ERASE_OP,  CLEAR_OP,      key_proc),
  730.     X    k(         "Sto",             "",          "Sto",             "",    STO_OP,     NO_OP,    STO_OP,     NO_OP,    store_proc),
  731.     X    k(         "Rcl",             "",          "Rcl",             "",    RCL_OP,     NO_OP,    RCL_OP,     NO_OP,   recall_proc),
  732.     X    k(         "Exc",             "",          "Exc",             "",    EXC_OP,     NO_OP,    EXC_OP,     NO_OP, exchange_proc),
  733.     X    k(           "(",             "",            "(",             "", LPAREN_OP,     NO_OP, LPAREN_OP,     NO_OP,      key_proc),
  734.     X    k(           ")",             "",            ")",             "", RPAREN_OP,     NO_OP, RPAREN_OP,     NO_OP,      key_proc),
  735.     X    k(          "EE",           "EE",             "",             "",  DIGIT_EE,  INVEE_OP,     NO_OP,     NO_OP,      key_proc),
  736.     X    k(           "X",             "",            "X",             "",    MUL_OP,     NO_OP,    MUL_OP,     NO_OP,      key_proc),
  737.     X    k(         "log",       "10\200",            "D",             "",    LOG_OP,    POW_OP,   DIGIT_D,     NO_OP,      key_proc),
  738.     X    k(          "ln",        "e\200",            "E",             "",     LN_OP,    EXP_OP,   DIGIT_E,     NO_OP,      key_proc),
  739.     X    k(       "y\200",     "\203\204",            "F",             "",    Y2X_OP,   ROOT_OP,   DIGIT_F,     NO_OP,      key_proc),
  740.     X    k(           "7",             "",            "7",             "",   DIGIT_7,     NO_OP,   DIGIT_7,     NO_OP,      key_proc),
  741.     X    k(           "8",             "",            "8",             "",   DIGIT_8,     NO_OP,   DIGIT_8,     NO_OP,      key_proc),
  742.     X    k(           "9",             "",            "9",             "",   DIGIT_9,     NO_OP,   DIGIT_9,     NO_OP,      key_proc),
  743.     X    k(        "\214",             "",         "\214",             "",    DIV_OP,     NO_OP,    DIV_OP,     NO_OP,      key_proc),
  744.     X    k(         "sin",       "sn\205",            "A",             "",    SIN_OP,   ISIN_OP,   DIGIT_A,     NO_OP,      key_proc),
  745.     X    k(         "cos",       "cs\205",            "B",             "",    COS_OP,   ICOS_OP,   DIGIT_B,     NO_OP,      key_proc),
  746.     X    k(         "tan",       "tn\205",            "C",             "",    TAN_OP,   ITAN_OP,   DIGIT_C,     NO_OP,      key_proc),
  747.     X    k(           "4",             "",            "4",             "",   DIGIT_4,     NO_OP,   DIGIT_4,     NO_OP,      key_proc),
  748.     X    k(           "5",             "",            "5",             "",   DIGIT_5,     NO_OP,   DIGIT_5,     NO_OP,      key_proc),
  749.     X    k(           "6",             "",            "6",             "",   DIGIT_6,     NO_OP,   DIGIT_6,     NO_OP,      key_proc),
  750.     X    k(           "+",             "",            "+",             "",    ADD_OP,     NO_OP,    ADD_OP,     NO_OP,      key_proc),
  751.     X    k(    "\202\201",        "x\206",           "<<",     "\217\220",   SQRT_OP,    SQR_OP,    LSL_OP,    ROL_OP,      key_proc),
  752.     X    k(    "\210\211",             "",          "Not",       "\221>>",   OVER_OP,     NO_OP,    NOT_OP,    RSA_OP,      key_proc),
  753.     X    k(          "x!",             "",           ">>",     "\215\216",   FACT_OP,     NO_OP,    RSL_OP,    ROR_OP,      key_proc),
  754.     X    k(           "1",             "",            "1",             "",   DIGIT_1,     NO_OP,   DIGIT_1,     NO_OP,      key_proc),
  755.     X    k(           "2",             "",            "2",             "",   DIGIT_2,     NO_OP,   DIGIT_2,     NO_OP,      key_proc),
  756.     X    k(           "3",             "",            "3",             "",   DIGIT_3,     NO_OP,   DIGIT_3,     NO_OP,      key_proc),
  757.     X    k(           "-",             "",            "-",             "",    SUB_OP,     NO_OP,    SUB_OP,     NO_OP,      key_proc),
  758.     X    k(        "\207",            "e",          "And",             "",     PI_OP,      E_OP,    AND_OP,     NO_OP,      key_proc),
  759.     X    k(         "Int",          "Trc",           "Or",          "Xor",    INT_OP,  TRUNC_OP,     OR_OP,    XOR_OP,      key_proc),
  760.     X    k(         "Fix",          "DRG",          "Fix",             "",    FIX_OP,    FIX_OP,    FIX_OP,     NO_OP,      fix_proc),
  761.     X    k(           ".",             "",             "",             "", DIGIT_DOT,     NO_OP,     NO_OP,     NO_OP,      key_proc),
  762.     X    k(           "0",             "",            "0",             "",   DIGIT_0,     NO_OP,   DIGIT_0,     NO_OP,      key_proc),
  763.     X    k(    "\212\213",             "",     "\212\213",             "", DIGIT_CHS,     NO_OP, DIGIT_CHS,     NO_OP,      key_proc),
  764.     X    k(           "=",             "",            "=",             "",  EQUAL_OP,     NO_OP,  EQUAL_OP,     NO_OP,      key_proc)
  765.     X    };
  766.     X
  767.     Xstatic    short    ct_icon_image[] = {
  768.     X#include    "calc.icon"
  769.     X};
  770.     Xmpr_static(ct_icon_pixrect, 47, 64, 1, ct_icon_image);
  771.     X
  772.     XPUBLIC    create_screen(argc, argv)
  773.     X
  774.     Xint    argc;
  775.     Xchar    **argv;
  776.     X
  777.     X{    int    i, j;
  778.     X    Icon    icon;
  779.     X
  780.     X    icon = icon_create(ICON_IMAGE, &ct_icon_pixrect, ICON_LABEL, NULL, ICON_WIDTH, 47, ICON_HEIGHT, 64, 0);
  781.     X    bf = window_create(NULL, FRAME,
  782.     X                  FRAME_ARGS, argc, argv,
  783.     X                  FRAME_LABEL, "<< Calctool >>",
  784.     X                  FRAME_ICON, icon,
  785.     X                  FRAME_SUBWINDOWS_ADJUSTABLE, FALSE,
  786.     X                  FRAME_NO_CONFIRM, TRUE,
  787.     X               0);
  788.     X    sw = window_create(bf, PANEL, 0);
  789.     X    display = window_create(bf, CANVAS, 0);
  790.     X    keys = window_create(bf, PANEL, 
  791.     X                WIN_WIDTH, 360,
  792.     X                PANEL_ACCEPT_KEYSTROKE, TRUE,
  793.     X                PANEL_BACKGROUND_PROC, kb_proc,
  794.     X                 0);
  795.     X
  796.     X    if ((key_font = pf_open(KEY_FONT)) == NULL) {
  797.     X       fprintf(stderr, "calctool: could not open font %s\n", KEY_FONT);
  798.     X       exit(1);
  799.     X       }
  800.     X    for (i = 0; i < FIRST_KEY; i++)
  801.     X       for (j = 0; j < 4; j++)
  802.     X          key[i].image[j] = panel_button_image((i == 0)? sw : keys, key[i].label[j], 7, key_font);
  803.     X    for (i = FIRST_KEY; i <= LAST_KEY; i++)
  804.     X       for (j = 0; j < 4; j += 2)
  805.     X          if (key[i].opcode[j] != NO_OP) {
  806.     X             key[i].image[j] = panel_button_image(sw, key[i].label[j], 3, key_font);
  807.     X             if (key[i].opcode[j + 1] == NO_OP) {
  808.     X                key[i].image[j + 1] = panel_button_image(sw, key[i].label[j], 3, key_font);
  809.     X                pr_replrop(key[i].image[j+1], 0, 0, key[i].image[j+1]->pr_width, key[i].image[j+1]->pr_height,
  810.     X                       PIX_SRC & PIX_DST, &mask, 0, 0);
  811.     X                }
  812.     X             else
  813.     X                key[i].image[j+1] = panel_button_image(sw, key[i].label[j+1], 3, key_font);
  814.     X             }
  815.     X
  816.     X    CLOSE_KEY.item = panel_create_item(sw, PANEL_BUTTON,
  817.     X                          PANEL_LABEL_IMAGE, CLOSE_KEY.image[0],
  818.     X                          PANEL_NOTIFY_PROC, CLOSE_KEY.proc,
  819.     X                          PANEL_EVENT_PROC, event_proc,
  820.     X                          PANEL_CLIENT_DATA, &(CLOSE_KEY),
  821.     X                       0);
  822.     X    window_fit(sw);
  823.     X
  824.     X    INVERSE_KEY.item = panel_create_item(keys, PANEL_BUTTON,
  825.     X                        PANEL_LABEL_IMAGE, INVERSE_KEY.image[0],
  826.     X                        PANEL_NOTIFY_PROC, INVERSE_KEY.proc,
  827.     X                            PANEL_EVENT_PROC, event_proc,
  828.     X                        PANEL_CLIENT_DATA, &(INVERSE_KEY),
  829.     X                         0);
  830.     X    key[FIRST_KEY].item = panel_create_item(keys, PANEL_BUTTON,
  831.     X                           PANEL_LABEL_IMAGE, key[FIRST_KEY].image[0],
  832.     X                           PANEL_NOTIFY_PROC, key[FIRST_KEY].proc,
  833.     X                               PANEL_EVENT_PROC, event_proc,
  834.     X                               PANEL_ACCEPT_KEYSTROKE, TRUE,
  835.     X                           PANEL_ITEM_X, panel_get(INVERSE_KEY.item, PANEL_ITEM_X),
  836.     X                           PANEL_ITEM_Y, panel_get(INVERSE_KEY.item, PANEL_ITEM_Y) + 
  837.     X                                    INVERSE_KEY.image[0]->pr_height + 4,
  838.     X                           PANEL_CLIENT_DATA, &(key[FIRST_KEY]),
  839.     X                        0);
  840.     X    for (i = FIRST_KEY + 1; i <= LAST_KEY; i++)
  841.     X       key[i].item = panel_create_item(keys, PANEL_BUTTON,
  842.     X                             PANEL_LABEL_IMAGE, key[i].image[0],
  843.     X                             PANEL_NOTIFY_PROC, key[i].proc,
  844.     X                          PANEL_EVENT_PROC, event_proc,
  845.     X                          PANEL_ACCEPT_KEYSTROKE, TRUE,
  846.     X                             PANEL_CLIENT_DATA, &(key[i]),
  847.     X                          0);
  848.     X    CLEAR_KEY.item = panel_create_item(keys, PANEL_BUTTON,
  849.     X                          PANEL_LABEL_IMAGE, CLEAR_KEY.image[0],
  850.     X                          PANEL_NOTIFY_PROC, CLEAR_KEY.proc,
  851.     X                          PANEL_EVENT_PROC, event_proc,
  852.     X                          PANEL_ITEM_X, panel_get(key[LAST_KEY].item, PANEL_ITEM_X) + 
  853.     X                                key[LAST_KEY].image[0]->pr_width - CLEAR_KEY.image[0]->pr_width,
  854.     X                          PANEL_ITEM_Y, panel_get(INVERSE_KEY.item, PANEL_ITEM_Y),
  855.     X                          PANEL_CLIENT_DATA, &(CLEAR_KEY),
  856.     X                       0);
  857.     X    panel_create_item(keys, PANEL_CHOICE,
  858.     X                 PANEL_LABEL_STRING, "",
  859.     X                 PANEL_DISPLAY_LEVEL, PANEL_CURRENT,
  860.     X                 PANEL_CHOICE_IMAGES, panel_button_image(keys, "Scientific", 13, key_font),
  861.     X                               panel_button_image(keys, "Engineering", 13, key_font),
  862.     X                               panel_button_image(keys, "Binary", 13, key_font),
  863.     X                               panel_button_image(keys, "Octal", 13, key_font),
  864.     X                               panel_button_image(keys, "Hexadecimal", 13, key_font),
  865.     X                               0,
  866.     X                 PANEL_CHOICE_XS, panel_get(key[FIRST_KEY + 2].item, PANEL_ITEM_X), 0,
  867.     X                 PANEL_CHOICE_YS, panel_get(INVERSE_KEY.item, PANEL_ITEM_Y), 0,
  868.     X/*                 PANEL_CHOICE_FONTS, key_font, 0,*/
  869.     X                 PANEL_NOTIFY_PROC, radix_proc,
  870.     X              0);
  871.     X    window_fit(keys);
  872.     X
  873.     X    window_set(sw,
  874.     X              WIN_X, 0,
  875.     X              WIN_Y, 0,
  876.     X           0);
  877.     X    window_set(display,
  878.     X              WIN_RIGHT_OF, sw,
  879.     X              WIN_Y, 0,
  880.     X              WIN_WIDTH, window_get(keys, WIN_WIDTH) - window_get(sw, WIN_WIDTH) - 5,
  881.     X              WIN_HEIGHT, window_get(sw, WIN_HEIGHT),
  882.     X           0);
  883.     X    window_set(keys,
  884.     X              WIN_X, 0,
  885.     X              WIN_BELOW, sw,
  886.     X           0);
  887.     X    window_fit(bf);
  888.     X    window_set(sw, 
  889.     X              WIN_WIDTH, window_get(sw, WIN_WIDTH),
  890.     X              WIN_HEIGHT, window_get(sw, WIN_HEIGHT),
  891.     X           0);
  892.     X    window_set(display, 
  893.     X              WIN_WIDTH, window_get(display, WIN_WIDTH),
  894.     X              WIN_HEIGHT, window_get(display, WIN_HEIGHT),
  895.     X           0);
  896.     X    window_set(keys, 
  897.     X              WIN_WIDTH, window_get(keys, WIN_WIDTH),
  898.     X              WIN_HEIGHT, window_get(keys, WIN_HEIGHT),
  899.     X           0);
  900.     X    update_display();
  901.     X    window_main_loop(bf);
  902.     X}
  903.     X
  904.     XPRIVATE    close_proc()
  905.     X
  906.     X{
  907.     X    if (inverted ^ temp_inverted) {
  908.     X       window_destroy(bf);
  909.     X       exit(0);
  910.     X       }
  911.     X    else {
  912.     X       window_set(bf, FRAME_CLOSED, TRUE, 0);
  913.     X       temp_inverted = FALSE;
  914.     X       if (inverted)
  915.     X          invert_proc();
  916.     X       }
  917.     X}
  918.     X
  919.     XPUBLIC    invert_proc()
  920.     X
  921.     X{    int    i;
  922.     X
  923.     X    temp_inverted = FALSE;
  924.     X    inverted = !inverted;
  925.     X    for (i = 0; i <= LAST_KEY; i++)
  926.     X       if (key[i].image[curr_mode + (inverted? 1 : 0)] && valid_key(key[i].opcode[curr_mode]))
  927.     X          panel_set(key[i].item, PANEL_LABEL_IMAGE, key[i].image[curr_mode + (inverted? 1 : 0)], PANEL_SHOW_ITEM, TRUE, 0);
  928.     X       else
  929.     X          panel_set(key[i].item, PANEL_SHOW_ITEM, FALSE, 0);
  930.     X}
  931.     X
  932.     XPRIVATE    radix_proc(item, value, event)
  933.     X
  934.     XPanel_item    item;
  935.     Xint        value;
  936.     XEvent        *event;
  937.     X
  938.     X{    int    i;
  939.     X    static    int    bases[] = {DECIMAL, DECIMAL, BINARY, OCTAL, HEXADECIMAL};
  940.     X
  941.     X    convert_display();
  942.     X    if (value == 0) {
  943.     X       curr_mode = SCIENTIFIC;
  944.     X       eng_mode = FALSE;
  945.     X       }
  946.     X    else if (value == 1) {
  947.     X       curr_mode = SCIENTIFIC;
  948.     X       eng_mode = TRUE;
  949.     X       }
  950.     X    else
  951.     X       curr_mode = PROGRAMMER;
  952.     X    curr_base = bases[value];
  953.     X    inverted = temp_inverted = FALSE;
  954.     X    for (i = FIRST_KEY; i <= LAST_KEY; i++)
  955.     X       if (key[i].opcode[curr_mode] != NO_OP && valid_key(key[i].opcode[curr_mode]))
  956.     X          panel_set(key[i].item, PANEL_LABEL_IMAGE, key[i].image[curr_mode], PANEL_SHOW_ITEM, TRUE, 0);
  957.     X       else
  958.     X          panel_set(key[i].item, PANEL_SHOW_ITEM, FALSE, 0);
  959.     X    update_display();
  960.     X}
  961.     X
  962.     XPRIVATE    event_proc(item, event)
  963.     X
  964.     XPanel_item    item;
  965.     XEvent        *event;
  966.     X
  967.     X{    key_ptr    ky;
  968.     X    static    key_ptr    curr_key;
  969.     X    int    op;
  970.     X
  971.     X    if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST) {
  972.     X       keyboard(event_id(event));
  973.     X       return;
  974.     X       }
  975.     X    ky = (key_ptr) panel_get(item, PANEL_CLIENT_DATA);
  976.     X    switch (event_id(event)) {
  977.     X       case MS_LEFT            : if (ky->opcode[curr_mode + (inverted? 1 : 0)] != NO_OP)
  978.     X                    if (event_is_down(event)) {
  979.     X                       panel_begin_preview(item, event);
  980.     X                       curr_key = ky;
  981.     X                       }
  982.     X                    else if (curr_key == ky) {
  983.     X                       panel_accept_preview(item, event);
  984.     X                       curr_key = NULL;
  985.     X                       }
  986.     X                     break;
  987.     X       case MS_MIDDLE          : if (ky->opcode[curr_mode + (inverted? 0 : 1)] != NO_OP)
  988.     X                    if (event_is_down(event)) {
  989.     X                       panel_set(item, PANEL_LABEL_IMAGE, ky->image[curr_mode + (inverted? 0 : 1)], 0);
  990.     X                       panel_begin_preview(item, event);
  991.     X                       curr_key = ky;
  992.     X                       }
  993.     X                    else if (curr_key == ky) {
  994.     X                       temp_inverted = TRUE;
  995.     X                       panel_accept_preview(item, event);
  996.     X                       panel_set(item, PANEL_LABEL_IMAGE, ky->image[curr_mode + (inverted? 1 : 0)], 0);
  997.     X                       curr_key = NULL;
  998.     X                       }
  999.     X                           break;
  1000.     X       case MS_RIGHT       : if (event_is_down(event))
  1001.     X                    if ((op = ky->opcode[curr_mode + (inverted? 1 : 0)]) == STO_OP ||
  1002.     X                         op == RCL_OP ||
  1003.     X                         op == EXC_OP ||
  1004.     X                         op == FIX_OP) {
  1005.     X                       panel_begin_preview(item, event);
  1006.     X                       panel_accept_preview(item, event);
  1007.     X                       }
  1008.     X                     break;
  1009.     X       case PANEL_EVENT_CANCEL : if (curr_key == ky) {
  1010.     X                    panel_cancel_preview(item, event);
  1011.     X                    panel_set(item, PANEL_LABEL_IMAGE, ky->image[curr_mode + (inverted? 1 : 0)], 0);
  1012.     X                    curr_key = NULL;
  1013.     X                    }
  1014.     X                     break;
  1015.     X       }
  1016.     X}
  1017.     X
  1018.     XPRIVATE    key_proc(item, event)
  1019.     X
  1020.     XPanel_item    item;
  1021.     XEvent        *event;
  1022.     X
  1023.     X{    key_ptr    ky;
  1024.     X    int    op;
  1025.     X
  1026.     X    ky = (key_ptr) panel_get(item, PANEL_CLIENT_DATA);
  1027.     X    op = ky->opcode[curr_mode + ((inverted? 1 : 0) ^ temp_inverted)];
  1028.     X    if (is_digit(op))
  1029.     X       do_digit(op);
  1030.     X    else if (is_binary(op))
  1031.     X       do_binary(op);
  1032.     X    else
  1033.     X       do_unary(op);
  1034.     X    temp_inverted = FALSE;
  1035.     X    if (inverted)
  1036.     X       invert_proc();
  1037.     X}
  1038.     X
  1039.     XPRIVATE    kb_proc(item, event)
  1040.     X
  1041.     XPanel_item    item;
  1042.     XEvent        *event;
  1043.     X
  1044.     X{
  1045.     X    if (event_id(event) >= ASCII_FIRST && event_id(event) <= ASCII_LAST)
  1046.     X       keyboard(event_id(event));
  1047.     X}
  1048.     X
  1049.     XPUBLIC    int    blink(op)
  1050.     X
  1051.     Xint    op;
  1052.     X
  1053.     X{    int    i, j;
  1054.     X    struct    pixrect    *old, *new;
  1055.     X
  1056.     X    for (i = FIRST_KEY; i <= LAST_KEY; i++)
  1057.     X       if (op == key[i].opcode[curr_mode])
  1058.     X          break;
  1059.     X    old = (struct pixrect *) panel_get(key[i].item, PANEL_LABEL_IMAGE);
  1060.     X    new = mem_create(old->pr_width, old->pr_height, 1);
  1061.     X    pr_rop(new, 0, 0, new->pr_width, new->pr_height, PIX_NOT(PIX_SRC), old, 0, 0);
  1062.     X    panel_set(key[i].item, PANEL_LABEL_IMAGE, new, 0);
  1063.     X    for (j = 25000; j; j--)
  1064.     X       ;
  1065.     X    panel_set(key[i].item, PANEL_LABEL_IMAGE, old, 0);
  1066.     X    pr_destroy(new);
  1067.     X    return(op);
  1068.     X}
  1069.     X
  1070.     Xmain(argc, argv)
  1071.     X
  1072.     Xint    argc;
  1073.     Xchar    **argv;
  1074.     X
  1075.     X{
  1076.     X    create_screen(argc, argv);
  1077.     X}
  1078. SHAR_EOF
  1079. if test 16521 -ne "`wc -c < 'screen.c'`"
  1080. then
  1081.     echo shar: error transmitting "'screen.c'" '(should have been 16521 characters)'
  1082. fi
  1083. fi # end of overwriting check
  1084. #    End of shell archive
  1085. exit 0
  1086.